﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace TestMonkey.Core.Templates
{
    public class PropertyWriteRead : PropertyTemplateProcessor
    {
        public override bool ShouldRun(Type type, PropertyInfo property)
        {
            return property.CanActuallyRead()
                && property.CanActuallyWrite()
                && property.GetIndexParameters().Count()==0
                && GetTrailer(property) != "";
        }

        private static string GetTrailer(PropertyInfo property)
        {
            if (property.PropertyType == typeof(Boolean)) return "-Boolean";
            if (property.PropertyType.IsMinMaxNumeric()) return "-Numeric";
            if (property.PropertyType == typeof(DateTime)) return "-Date";
            if (property.PropertyType == typeof(DateTimeOffset)) return "-Date";
            if (property.PropertyType == typeof(String)) return "-String";
            

            return "";
        }

        public override string PartialTemplateFileName(Type type, PropertyInfo property)
        {
            string trailer = GetTrailer(property);
            return base.PartialTemplateFileName(type, property) + trailer;
        }
    }
}
